#!/usr/bin/env node

const http = require('http');

http.createServer((req,res)=>{

  console.log(req.headers);
  console.log(`${req.method} ${req.url} HTTP/${req.httpVersion}`);
  console.log(req.headers);
  console.log('');

  console.log('Host:',req.headers.host);
  console.log('User-Agent:',req.headers['user-agent']);
  console.log('Content-Type:', req.headers['content-type']);
  console.log('');

  console.log('authorization:',req.headers.authorization);

  let auth = req.headers.authorization;
  console.log('auth',auth);

  if(typeof auth !== 'undefined'){
    auth = auth.split(' ');
    if(auth[0] === 'Basic'){
      let buf = new Buffer(auth[1],'base64');
      console.log('buf',buf);
      console.log('username & password',buf.toString('utf8'));
    }
  }
  res.end('OK');
}).listen(8080);


